//该文件专门用于创建整个应用的路由器

import VueRouter from 'vue-router';

//引入组件
import About from "../pages/About.vue";
import Home from "../pages/Home.vue";
import News from '../pages/News.vue'
import Messages from '../pages/Message.vue'
import Detail from '../pages/Detail.vue'

//创建并暴露一个路由器
export default new VueRouter({
    routes: [
        {
            path: '/',
            // redirect:'/about'//路由重定向用于初次访问时切换到指定路由，1：path，写法2：对象写法
            redirect: {
                name: 'guanyu'
            }
        },
        {
            name: 'guanyu',//给路由命名，可以简化跳转时候的路径书写，不用path配置项用name配置项,必须配合to的对象写法
            path: '/about',
            component: About
        },
        {
            path: '/home',
            component: Home,
            children: [//嵌套路由
                {
                    path: 'news',//子路由不用加'/'或者写全/home/news
                    component: News
                },
                {
                    path: 'messages',
                    component: Messages,
                    children: [
                        {
                            name: 'xiangqing',
                            path: 'detail',
                            component: Detail
                        }
                    ]
                },
            ]
        },
    ]
});
